<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="房东姓名">
          <a-input placeholder="请输入房东姓名" v-decorator="['landlordName', {rules: [{ required: true, message: 'Please input landlord name !' }],}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="联系方式">
          <a-input placeholder="请输入联系方式" v-decorator="['landlordContact', {rules: [{ required: true, message: 'Please input your phone number!' }]}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="楼房名称">
          <a-input placeholder="请输入楼房名称" v-decorator="['floorName', {rules: [{ required: true, message: 'Please input floor name !' }]}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="房屋房间统计">
          <a-input placeholder="请输入房屋房间统计" v-decorator="['bedroomCount', {rules: [{ required: true, message: 'Please input bedroom count  !' }],}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="房屋卫生间统计">
          <a-input placeholder="请输入房屋卫生间统计" v-decorator="['bathroomCount', {rules: [{ required: true, message: 'Please input bathroom count !' }],}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="房屋客厅统计">
          <a-input placeholder="请输入房屋客厅统计" v-decorator="['livingroomCount', {rules: [{ required: true, message: 'Please input livingroom count !' }],}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="出租价格">
          <a-input placeholder="请输入出租价格" v-decorator="['rentalPrices', {rules: [{ required: true, message: 'Please input  rental prices !' }],}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="房屋面积">
          <a-input placeholder="请输入房屋面积" v-decorator="['housesSpace', {rules: [{ required: true, message: 'Please input houses space !' }],}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="房屋概况图片">
          <a-input placeholder="请输入房屋概况图片" v-decorator="['housesCover', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="装修类型">
          <!-- <a-input placeholder="请输入装修类型" v-decorator="['decorateType', {}]" /> -->
          <a-select
            style="width: 200px"
            @change="handleChange"
            v-decorator="[ 'decorateType', {}]"
          >
            <a-select-option v-for="item in decorateType" :key="item">
              {{item}}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <!-- <a-input-number v-decorator="[ 'applyStatus', {}]" /> -->
          <a-select
            style="width: 200px"
            @change="handleChange"
            v-decorator="[ 'applyStatus', {}]"
          >
            <a-select-option v-for="item in appleStatus" :key="item">
              {{item}}
            </a-select-option>
          </a-select>
        </a-form-item>
		
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "LandlordModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/landlord/landlord/add",
          edit: "/landlord/landlord/edit",
        },
        decorateType:['毛坯房','简装修','中装修','精装修'],
        // appleStatus:[[{name:'待审核',value:1}],[{name:'申请通过',value:2}],[{name:'申请不通过',value:3}]]
        appleStatus:['待审核','申请通过','申请不通过'],
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'landlordName','landlordContact','floorName','bedroomCount','bathroomCount','livingroomCount','rentalPrices','housesSpace','housesCover','decorateType','applyStatus'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            if(formData.applyStatus==="申请通过"){
              formData.applyStatus = 2
            }else if(formData.applyStatus==="申请通过"){
              formData.applyStatus = 3
            }else{
              formData.applyStatus = 1
            }
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },
      handleChange(value) {
        // console.log(`Selected: ${value}`);
      },

    }
  }
</script>

<style lang="less" scoped>

</style>